package com.dabao.service.impl;

import com.dabao.bean.Menu;
import com.dabao.bean.Role;
import com.dabao.dao.RoleDao;
import com.dabao.query.RoleQuery;
import com.dabao.service.RoleService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by kakalee on 16/4/24.
 */
@Service
public class RoleServiceImpl extends BaseServiceImpl<Role, RoleQuery> implements RoleService{

    public List<Menu> selectMenus(Integer id) {
        RoleDao roleDao = (RoleDao) dao;
        return roleDao.selectMenus(id);
    }

    @Transactional
    public int addMenus(Integer id, Integer[] menuIds) {
        RoleDao roleDao = (RoleDao) dao;
        roleDao.deleteRoleMenu(id);
        if(menuIds != null) {
            for (int i = 0; i < menuIds.length; i++) {
                roleDao.insertRoleMenu(id, menuIds[i]);
            }
        }
        return 1;
    }
}
